package com.yycx.module.bus.provider.handler.haiying.order.waybill;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.security.OpenHelper;
import com.yycx.common.utils.DateUtils;
import com.yycx.module.bus.client.entity.BusCustom;
import com.yycx.module.bus.client.entity.BusDept;
import com.yycx.module.bus.client.entity.hy.HyOrder;
import com.yycx.module.bus.client.entity.hy.HyOrderDetail;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 已打印商品标签打印
 *
 * @author zyf
 */
@Component
public class HyWaybillTab4ListHandler implements PageInterceptor<HyOrderDetail> {


    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, PageParams pageParams, EntityMap params) {
        String beginDate = params.get("beginDate", DateUtils.formatDate());
        cq.clear();
        cq.select(HyOrderDetail.class,"orderDetailsId","drugsName","storeName","drugsSpec","drugLotNo","format(drugJs,2) drugJs","CEILING(drugJs) drugJsCount","outPrintTag");
        cq.select(HyOrder.class,"orderId","outOrderNo","sendDate","saleManName");
        cq.select(BusDept.class,"deptName");
        cq.select(BusCustom.class,"customName");
        String orderNo=cq.getParams("orderNo");
        if(FlymeUtils.isNotEmpty(orderNo)) {
            cq.like("ho.outOrderNo", orderNo);
        }
        cq.eq(HyOrder.class, "companyId",OpenHelper.getCompanyId());
        cq.eq("ho.orderState", 2);
        cq.gt("ho.outPrintTag", 0);
        cq.gt("bhd.outPrintTag", 0);
        cq.eq("ho.sendDate",beginDate);
        cq.createJoin(BusDept.class);
        cq.createJoin(BusCustom.class);
        cq.like(HyOrder.class,"customAddress");
        cq.orderByDesc("ho.createTime");
    }

    @Override
    public List<EntityMap> complete(CriteriaQuery<HyOrderDetail> cq, List<EntityMap> result, EntityMap extra) {

        return result;
    }

}
